package cglib;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class DongTaiTest implements InvocationHandler
{

    private Object o;
    public DongTaiTest(Object o)
    {
        this.o = o;
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
    {
        System.out.println("before calling:" + method);
        //调用这个对象
        method.invoke(this.o, args);

        System.out.println("after calling:" + method);
        return null;
    }

    public Object getInterface()
    {
        Class<?> cls = o.getClass();
        return Proxy.newProxyInstance(cls.getClassLoader(), cls.getInterfaces(), this);
    }
}
